from django.contrib import admin
from .models import Like, Comment


@admin.register(Like)
class LikeAdmin(admin.ModelAdmin):
    """点赞管理"""
    list_display = ['id', 'user', 'artwork', 'created_at']
    list_filter = ['created_at']
    search_fields = ['user__username', 'artwork__title']
    readonly_fields = ['created_at']
    list_per_page = 20
    date_hierarchy = 'created_at'


@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    """评论管理"""
    list_display = ['id', 'user', 'artwork', 'content_preview', 'created_at']
    list_filter = ['created_at']
    search_fields = ['user__username', 'artwork__title', 'content']
    readonly_fields = ['created_at']
    list_per_page = 20
    date_hierarchy = 'created_at'
    
    def content_preview(self, obj):
        """评论内容预览"""
        return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
    content_preview.short_description = '评论内容'
